import 'package:flutter/material.dart';
import '../demo/ui_demo.dart';

class MyDemo extends StatelessWidget implements Demo {
  MyDemo(this.title);
  @override
  String title;
  @override
  Widget build(BuildContext context) {
    return new HomePage(title: this.title,);
  }
}

class HomePage extends StatelessWidget {
  String title;
  HomePage({this.title});

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 3,
      child: Scaffold(
        appBar: AppBar(
          title: Text(this.title),
          centerTitle: true,
          elevation: 0,
          actions: <Widget>[
            IconSource("BoxDecoration","04"),
          ],
        ),
        body: ListView(
          padding: EdgeInsets.only(left: 10.0),
          children: <Widget>[
            TextDemo(),
            RichTextDemo(),
            BoxDecorationDemo(),
            BoxDecorationDemo2(),
          ],
        ),
      ),
    );
  }
}

class TextDemo extends StatelessWidget {
  TextStyle _textStyle =
      TextStyle(color: Colors.black54, fontWeight: FontWeight.bold);
  final String _author = "李清照";
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      margin: EdgeInsets.only(bottom: 10.0),
      child: Column(
        children: <Widget>[
          ListTile(
            title: Text("Text"),
            contentPadding: EdgeInsets.all(0.0),
          ),
          Text(
            "作者--$_author 生当作人杰，死亦为鬼雄。至今思项羽，不肯过江东。",
            style: _textStyle,
            textAlign: TextAlign.left,
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
          ),
        ],
      ),
    );
  }
}

class RichTextDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      margin: EdgeInsets.only(bottom: 10.0),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          ListTile(
            title: Text("RichText"),
            contentPadding: EdgeInsets.all(0.0),
          ),
          RichText(
            textAlign: TextAlign.center,
            maxLines: 4,
            overflow: TextOverflow.ellipsis,
            text: TextSpan(
                text: "念奴娇赤壁怀古",
                style: TextStyle(
                    color: Colors.black87, fontWeight: FontWeight.bold),
                children: [
                  TextSpan(
                      text: "--苏轼\n",
                      style: TextStyle(fontStyle: FontStyle.italic)),
                  TextSpan(
                      text: "大江东去，浪淘尽，千古风流人物。故垒西边，人道是，三国周郎赤壁。"
                          "乱石穿空，惊涛拍岸，卷起千堆雪。江山如画，一时多少豪杰。"
                          "遥想公瑾当年，小乔初嫁了，雄姿英发。羽扇纶巾，谈笑间，樯橹灰飞烟灭"
                          "故国神游，多情应笑我，早生华发。\n",
                      style: TextStyle(fontWeight: FontWeight.normal)),
                ]),
          )
        ],
      ),
    );
  }
}

class BoxDecorationDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      child: Column(
        children: <Widget>[
          ListTile(
            title: Text("BoxDecoration"),
            contentPadding: EdgeInsets.all(0.0),
          ),
          Container(
            //color: Colors.blueAccent,
            child: Icon(
              Icons.pool,
              color: Colors.white,
              size: 50,
            ),
            width: 100.0,
            height: 100.0,
            decoration: BoxDecoration(
                color: Colors.blueAccent,
//              border: Border(
//                bottom: BorderSide(
//                  width: 2.0,
//                  color: Colors.black26,
//                  style: BorderStyle.solid
//                )
//              )
                border: Border.all(
                    width: 2.0,
                    color: Colors.black26,
                    style: BorderStyle.solid),
                //borderRadius: BorderRadius.circular(24.0),//圆角效果
                shape: BoxShape.circle,//改变box形状，circle不能与borderRadius同时用
//                gradient: RadialGradient(//径向渐变
//                  colors: [
//                    Color.fromRGBO(7, 102, 155, 1),
//                    Color.fromRGBO(3, 28, 128, 1),
//                  ]
//                ),
                gradient: LinearGradient(//线性渐变
                  colors: [
                    Color.fromRGBO(7, 102, 155, 1),
                    Color.fromRGBO(3, 28, 128, 1),
                  ],
                  begin: Alignment.topCenter,
                  end: Alignment.bottomRight
                ),
                boxShadow: <BoxShadow>[ //阴影
                  BoxShadow(
                    offset: Offset(0.0, 12.0), //x,y轴的偏移
                    color: Colors.blueGrey, //阴影颜色
                    blurRadius: 25.0, //模糊程度
                    spreadRadius: 4.0//阴影扩散程度
                  ),
                ]),
          )
        ],
      ),
    );
  }
}

class BoxDecorationDemo2 extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      child: Column(
        children: <Widget>[
          ListTile(title: Text("BoxDecoration（背景）"),contentPadding: EdgeInsets.all(0.0),),
          Container(
            width: 450.0,
            height: 250.0,
            child: Icon(Icons.pool,size: 100,color: Colors.blueAccent,),
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage("assets/images/3.jpg"),
                fit: BoxFit.fill,
                colorFilter: ColorFilter.mode(
                    Colors.black54,
                    BlendMode.lighten//混合模式
                )
              )
            ),
          ),
        ],
      ),
    );
  }
}